package GUI;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Font;
import java.io.IOException;
import java.util.Vector;

import javax.swing.JButton;
import javax.swing.JOptionPane;

import DataObjects.AreYouSure;
import Messages.MessageDeleteSupplier;
import Messages.MessageGetSupplierById;
import Messages.MessageGetSupplierByIdReply;
import Messages.MessageShowAllSuppliers;
import Messages.MessageShowAllSuppliersReply;

public class PanelFunctionInventoryThis extends PanelFunctionsEmpty {
	/**
	 * @author Alex
	 * @since 9.12.12
	 */

	private static final long serialVersionUID = 1L;
	private MainMenu mainMenu;
	private Vector<String> item;
	private Vector<Vector> items;
	private JButton button_editItem;
	private JButton button_orderItem;
	private JButton button_deleteItem;
	private AreYouSure areyousure;
	private Integer answerDelItem=0;
	String IDItem;
	
	
public PanelFunctionInventoryThis(MainMenu mm,Vector<String> item)
{
	super();
	this.item=item;
	this.mainMenu=mm;
	this.add(get_button_editItem());
	this.add(get_button_order_item());
	this.add(get_button_deleteItem(item));
	}
	
	
private JButton get_button_order_item() 
{
	if (button_orderItem == null) 
	{			
		button_orderItem=new JButton("להזמין פריט");  			 
		button_orderItem.setFont(new Font("Tahoma", Font.BOLD | Font.ITALIC, 15));
		button_orderItem.setPreferredSize(new Dimension(220, 30));
		
		button_orderItem.addActionListener(new java.awt.event.ActionListener() 
		   {
			public void actionPerformed(java.awt.event.ActionEvent e) 
			{
				mainMenu.getContentPane().remove(((BorderLayout)mainMenu.getContentPane().getLayout()).getLayoutComponent(BorderLayout.CENTER));
				mainMenu.getContentPane().add(new PfAdd_items_to_supplier(mainMenu,item.get(0)), BorderLayout.CENTER);					
				mainMenu.getContentPane().validate();						
			}
		});
	}
	return button_orderItem;
}





	
	
private JButton get_button_editItem() 
	{
		if (button_editItem == null) 
		{			
			button_editItem=new JButton("לעדכן פריט");  			 
			button_editItem.setFont(new Font("Tahoma", Font.BOLD | Font.ITALIC, 15));
			button_editItem.setPreferredSize(new Dimension(220, 30));
			
			button_editItem.addActionListener(new java.awt.event.ActionListener() 
			   {
				public void actionPerformed(java.awt.event.ActionEvent e) 
				{
					mainMenu.getContentPane().remove(((BorderLayout)mainMenu.getContentPane().getLayout()).getLayoutComponent(BorderLayout.CENTER));
					MessageGetSupplierById getUser=new MessageGetSupplierById(item.get(0));
					try {
						mainMenu.ms.client.sendToServer(getUser);	
					    MessageGetSupplierByIdReply result=(MessageGetSupplierByIdReply)mainMenu.ms.client.GetMessage();
					    mainMenu.getContentPane().add(new PfUpdate_supplier(mainMenu,result.getSupplier()), BorderLayout.CENTER);
					    mainMenu.getContentPane().validate();
					    }	
					catch (IOException e1) {
						// TODO Auto-generated catch block
						e1.printStackTrace();
					}
				
				}
			});
			
			
		}
		return button_editItem ;
	}
	
	
	
	
private JButton get_button_deleteItem(final Vector<String> sup) 
	{
		if (button_deleteItem == null) 
		{			
			button_deleteItem=new JButton("למחוק פריט");  			 
			button_deleteItem.setFont(new Font("Tahoma", Font.BOLD | Font.ITALIC, 15));
			button_deleteItem.setPreferredSize(new Dimension(220, 30));
			
			button_deleteItem.addActionListener(new java.awt.event.ActionListener() 
			   {
				public void actionPerformed(java.awt.event.ActionEvent e) 
				{
					
					
					int n = JOptionPane.showConfirmDialog(
						    null,
						    "    אתה בטוח?",
						    "    בקשת אישור  ",
						    JOptionPane.YES_NO_OPTION);
					 //Object selectedValue = pane.getValue();
					 if(n==1){
						 
					 }
					 else{
						IDItem= sup.get(0);
						MessageDeleteSupplier msgDelSupp=new MessageDeleteSupplier (IDItem);
						try {
							mainMenu.ms.client.sendToServer(msgDelSupp);
							mainMenu.getContentPane().remove(((BorderLayout)mainMenu.getContentPane().getLayout()).getLayoutComponent(BorderLayout.CENTER));
							MessageShowAllSuppliers msgShowSupp=new MessageShowAllSuppliers( );
							mainMenu.ms.client.sendToServer(msgShowSupp);
							MessageShowAllSuppliersReply resultSupp=(MessageShowAllSuppliersReply)mainMenu.ms.client.GetMessage();
							mainMenu.getContentPane().add(new PfSearch_supplier(mainMenu,resultSupp.getResult()), BorderLayout.CENTER);	
							
							
							
							mainMenu.getContentPane().validate();
						}
						catch (IOException e1) {
							// TODO Auto-generated catch block
							e1.printStackTrace();
						
						
						
						
						}
								
								
						
					 
					
					   
				
				}}
			});
		}
		return button_deleteItem;
	}
	

}
